<?php

namespace app\dao\store;

use app\dao\BaseDao;
use app\model\store\Banner;

class BannerDao extends BaseDao
{
    protected function setModel(): string
    {
        return Banner::class;
    }

    /**
     * @return array
     * @throws \ReflectionException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * 获取banner列表
     */
    public function getBannerList(array $where = [], array $field = ['*'], int $num = 0, int $page = 0, int $limit = 0)
    {

        return $this->search($where)
            ->field($field)
            ->when($num, function ($query) use ($num) {
                $query->limit($num);
            })
            ->when($page, function ($query) use ($page, $limit) {
                $query->page($page, $limit);
            })
            ->order('sort desc')
            ->select()->toArray();
    }
}